package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.dao.ChapterDao;
import com.qf.entity.TbChapter;
import com.qf.service.ChapterService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 王希卓
 * @Date 2023/7/18 16:29
 * 课程章节业务实现
 */
@Service
public class ChapterServiceImpl extends ServiceImpl<ChapterDao, TbChapter> implements ChapterService {

    @Autowired(required = false)
    private ChapterDao chapterDao;
    /**
     * 根据课程id查询所有章节
     * @param courseId 课程id
     * @return
     */
    @Override
    public ResultMsg findByCourseId(int courseId) {

        QueryWrapper<TbChapter> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id",courseId);
        wrapper.orderByAsc("chapter_order");
        List<TbChapter> list = this.list(wrapper);
        return ResultMsg.success(list);
    }
}
